﻿@using TbShop.Web.Helpers;
@using TbShop;
@{
    var moduleName = ViewBag.ModuleName;
    var controllerName = ViewBag.ControllerName as string;
    ViewBag.Title = moduleName + "管理";
    var isAdd = true;//AuthorizationHelper.IsAuthorised(Constants.AuthorityIdentity.AddBanner);
    var isEdit = true;// AuthorizationHelper.IsAuthorised(Constants.AuthorityIdentity.EditBanner);
    var isDel = true;//AuthorizationHelper.IsAuthorised(Constants.AuthorityIdentity.DeleteBanner);
    var isSubscribe = true;
}

@Html.AntiForgeryToken()
<div class="panel panel-default">
    <div class="panel-heading">
        <strong>@ViewBag.Title</strong>
        <div class="pull-right">
            @if (isAdd)
            {
                <a href="@(Url.Action("Edit", controllerName))"><span class='glyphicon glyphicon-plus' aria-hidden='true'></span> 添加@(moduleName)</a>
            }
        </div>
    </div>
    <div class="panel-body">
        <table id="list_table"></table>
    </div>
</div>

@section scripts{
    @Styles.Render("~/bundles/editable-table-css")
    @Scripts.Render("~/bundles/editable-table")
    <script type="text/javascript">
        var categoryString = '@(Newtonsoft.Json.JsonConvert.SerializeObject(ViewBag.Categories))'.replaceAll("&quot;",'"');
        var categorys = JSON.parse(categoryString);
        function deleteData(id, vnum) {
            showConfirm("确认要删除该@(moduleName)？", function () {
            $.ajax({
                url: "@Url.Action("DeleteData")",
                type: "POST",
                data: AntiCSRF({ id: id, versionNumber: vnum }),
                dataType: "JSON",
                success: function (data) {
                    if (data == "1") {
                        window.location.reload();
                    }
                    else if (data == "-1") {
                        show_message('数据已被更改，请刷新后重试！', 'warning');
                    } else {
                        show_message('删除失败', 'warning');
                    }
                }
            });
        }, function () { });
    }

    $(function () {
        $('#list_table').bootstrapTable({
            columns: [{
                title: '名称',
                field: 'Name'
            }, {
                title: '淘宝编码',
                field: 'TbCode'
            }, {
                title: '上级编号',
                field: 'ParentId'
            }, {
                title: '序号',
                field: 'Sort'
            }, 
            {
                title: '添加时间',
                field: 'CreatedDate',
                formatter: function (value, row, index) {
                    return value.format("yyyy-MM-dd hh:mm");
                }
            }, {
                title: '操作',
                field: 'Id',
                formatter: function (value, row, index) {
                    return ('@(isEdit ? "true" : "false")' == 'true' ? '<a data-id="' + value + '" href="@(Url.Action("Edit"))?id=' + value + '" ><i class="glyphicon glyphicon-edit">修改</i><a>&nbsp;&nbsp;' : '') +
                        ('@(isDel ? "true" : "false")' == 'true' ? '<a data-id="' + value + '" href="javascript:void(0)" onclick="deleteData(' + value + ',' + row.VersionNumber + ')"><i class="glyphicon glyphicon-trash">删除</i><a>&nbsp;&nbsp;' : '');
                }
            }
            ],
            idField: 'Id',
            pagination: true,
            sidePagination: 'server',
            url: '@Url.Action("GetDataList")',
            queryParamsType: '',
            queryParams: function (params) {
                return params;
            },
            locale: 'zh-CN'
        });
    });
    </script>
}

